import bridge from "./dsbridge.js"
import UserInfoManager from "./UserInfoManager.js"

let AppBridge = {
	nativeRegister:function(){
		//原生调用js方法
		console.log("Native:注册原生方法")
		dsBridge.register('nativeInvokeJs', function (jsonStr) {
		        //js执行相关操作
			console.log("收到:"+jsonStr);
			let jsonObj = JSON.parse(jsonStr);
			let cmd = parseInt(jsonObj.cmd);
			if (cmd == 2){
				//获取sessionkey成功
				UserInfoManager.requestUserDetailInfo(jsonObj.token);
			}else if (cmd == 11){
				//收到广告播放完成的奖励--
				AppBridge.refreshUIAdPlayFinished();
			}
		        return "this is js json string.";
		    })
	},
	// 章节收费，请app播放广告
	jsRequestNativieToplayerAdsCmd010:function(productId,chapterId,complete) { 
		//nav启动就去原生获取token
		let paramJson = {plartform:"js",pro_version:"0.1",cmd:"010",description:"js请求原生播放广告","productId":productId,"chapterId":chapterId};
		console.log("发送:"+paramJson);
		dsBridge.call("jsInvokeNative", paramJson)
	},
	adPlayerComplete:function() {
		
	},
	nativeRquestSessionkeyCmd001:function(){ 
		//nav启动就去原生获取token
		let paramJson = {plartform:"js",pro_version:"0.1",cmd:"001",description:"js请求原生登录给到sessionkey"};
		console.log("发送:"+paramJson);
		dsBridge.call("jsInvokeNative", paramJson)
	},
	requestNativeGoAppStoreReviewsCmd003:function(){
		//原生去Appstore打分评论
		let paramJson = {plartform:"js",pro_version:"0.1",cmd:"003",description:"js请求原生登录给到sessionkey"};
		console.log("发送:"+paramJson);
		dsBridge.call("jsInvokeNative", paramJson)
	}
}

export default AppBridge